1 #include "LevelSelect.h"
3 #include "ScreenNames.h"
4 #include "RescourceKeys.h"
6 //Display boxes with clear ratings { F, C-, B, A+}
7 LevelSelect::LevelSelect(){}
9 LevelSelect::LevelSelect(int* screenPointer
, FileIO
* filePntr
, ResourceMaster
* resourcePntr
)
11 screen
= screenPointer
;
13 renderer
= rsc
->rendPtr
;
16 outlineAnimation
= new Animation(rsc
->gameAnimations
.at(0));
18 numUserData
= fio
->loadUserData(LevelUnlocks
);
19 numUserScores
= fio
->loadUserData(LevelScores
);
21 boxSize
= { 100, 100, 100, 100 };
23 font
= new Fonts(0, resourcePntr
);
25 int textSizeX
= font
->prcnt(0.20, 'x');
26 int textSizeY
= font
->prcnt(0.15, 'y');
27 int textAlignX
= font
->prcnt(0.55, 'x');
28 int textOffsetY
= font
->prcnt(0.05, 'y');
30 int generalSpaceY
= font
->prcnt(0.15, 'y');
32 int boxSizeX
= font
->prcnt(0.10, 'x');
33 int boxSizeY
= font
->prcnt(0.10, 'y');
34 int boxAlignX
= font
->prcnt(0.85, 'x');
35 int boxOffsetY
= font
->prcnt(0.08, 'y');
37 if ((numUserData
% 10) / 1 > 0) {
38 level1Selectable
= true;
39 font
->loadFont(SDL_Color
{ 200,200,200,00 }, rsc
->gameText
.at(Level1Text
), 2);
40 rectLevel1Box
= { boxAlignX
, generalSpaceY
* 0 + boxOffsetY
,boxSizeX
,boxSizeY
};
42 int score
= (numUserScores
% 10) / 1;
44 textLevel1Box
= rsc
->gameGraphics
.at(GradeF
);
46 else if (score
== 2) {
47 textLevel1Box
= rsc
->gameGraphics
.at(GradeC
);
49 else if (score
== 3) {
50 textLevel1Box
= rsc
->gameGraphics
.at(GradeB
);
52 else if (score
== 4) {
53 textLevel1Box
= rsc
->gameGraphics
.at(GradeA
);
57 font
->loadFont(SDL_Color
{ 100,100,100,128 }, rsc
->gameText
.at(Level1Text
), 2);
59 textLevel1
= font
->getTexture();
60 rectLevel1
= { textAlignX
,generalSpaceY
* 0 + textOffsetY
,textSizeX
,textSizeY
};
62 if ((numUserData
% 100) / 10 > 0) {
63 level2Selectable
= true;
64 font
->loadFont(SDL_Color
{ 200,200,200,00 }, rsc
->gameText
.at(Level2Text
), 2);
65 rectLevel2Box
= { boxAlignX
,generalSpaceY
* 1 + boxOffsetY
,boxSizeX
,boxSizeY
};
67 int score
= (numUserScores
% 100) / 10;
69 textLevel2Box
= rsc
->gameGraphics
.at(GradeF
);
71 else if (score
== 2) {
72 textLevel2Box
= rsc
->gameGraphics
.at(GradeC
);
74 else if (score
== 3) {
75 textLevel2Box
= rsc
->gameGraphics
.at(GradeB
);
77 else if (score
== 4) {
78 textLevel2Box
= rsc
->gameGraphics
.at(GradeA
);
82 font
->loadFont(SDL_Color
{ 100,100,100,128 }, rsc
->gameText
.at(Level2Text
), 2);
84 textLevel2
= font
->getTexture();
85 rectLevel2
= { textAlignX
,generalSpaceY
* 1 + textOffsetY
,textSizeX
,textSizeY
};
87 if ((numUserData
% 1000) / 100 > 0) {
88 level3Selectable
= true;
89 font
->loadFont(SDL_Color
{ 200,200,200,00 }, rsc
->gameText
.at(Level3Text
), 2);
90 rectLevel3Box
= { boxAlignX
,generalSpaceY
* 2 + boxOffsetY
,boxSizeX
,boxSizeY
};
92 int score
= (numUserScores
% 1000) / 100;
94 textLevel3Box
= rsc
->gameGraphics
.at(GradeF
);
96 else if (score
== 2) {
97 textLevel3Box
= rsc
->gameGraphics
.at(GradeC
);
99 else if (score
== 3) {
100 textLevel3Box
= rsc
->gameGraphics
.at(GradeB
);
102 else if (score
== 4) {
103 textLevel3Box
= rsc
->gameGraphics
.at(GradeA
);
107 font
->loadFont(SDL_Color
{ 100,100,100,128 }, rsc
->gameText
.at(Level3Text
), 2);
110 textLevel3
= font
->getTexture();
111 rectLevel3
= { textAlignX
,generalSpaceY
* 2 + textOffsetY
,textSizeX
,textSizeY
};
113 if ((numUserData
% 10000) / 1000 > 0) {
114 level4Selectable
= true;
115 font
->loadFont(SDL_Color
{ 200,200,200,00 }, rsc
->gameText
.at(Level4Text
), 2);
116 //rectLevel4Box = { boxAlignX,generalSpaceY * 3 + boxOffsetY,boxSizeX ,boxSizeY };
118 int score
= (numUserScores
% 10000) / 1000;
120 //textLevel4Box = rsc->gameGraphics.at(GradeF);
122 else if (score
== 2) {
123 //textLevel4Box = rsc->gameGraphics.at(GradeC);
125 else if (score
== 3) {
126 //textLevel4Box = rsc->gameGraphics.at(GradeB);
128 else if (score
== 4) {
129 //textLevel4Box = rsc->gameGraphics.at(GradeA);
133 font
->loadFont(SDL_Color
{ 100,100,100,128 }, rsc
->gameText
.at(Level4Text
), 2);
136 //textLevel4 = font->getTexture();
137 //rectLevel4 = {textAlignX,generalSpaceY * 3 + textOffsetY,textSizeX,textSizeY };
140 if ((numUserData
% 100000) / 10000 > 0) {
141 remixSelectable
= true;
142 font
->loadFont(SDL_Color
{ 200,200,200,00 }, rsc
->gameText
.at(RemixText
), 2);
143 //rectRemixBox = { boxAlignX,generalSpaceY * 4 + boxOffsetY,boxSizeX ,boxSizeY };
145 int score
= (numUserScores
% 100000) / 10000;
147 //textRemixBox = rsc->gameGraphics.at(GradeF);
149 else if (score
== 2) {
150 //textRemixBox = rsc->gameGraphics.at(GradeC);
152 else if (score
== 3) {
153 //textRemixBox = rsc->gameGraphics.at(GradeB);
155 else if (score
== 4) {
156 //textRemixBox = rsc->gameGraphics.at(GradeA);
160 font
->loadFont(SDL_Color
{ 100,100,100,128 }, rsc
->gameText
.at(RemixText
), 2);
162 //textRemix = font->getTexture();
163 //rectRemix = {textAlignX, generalSpaceY * 4 + textOffsetY,textSizeX,textSizeY };
165 font
->loadFont(SDL_Color
{ 200,200,200,00 }, rsc
->gameText
.at(BackText
), 2);
166 textQuit
= font
->getTexture();
167 rectQuit
= { textAlignX
,generalSpaceY
* 3 + textOffsetY
,textSizeX
,textSizeY
};
173 LevelSelect::~LevelSelect()
177 void LevelSelect::update()
186 if (x
> rectQuit
.x
&& y
> rectQuit
.y
) {
190 // else if (x > rectRemix.x && y > rectRemix.y && remixSelectable) {
192 // hoverRemix = true;
194 // else if (x > rectLevel4.x && y > rectLevel4.y && level4Selectable) {
196 // hoverLevel4 = true;
198 else if (x
> rectLevel3
.x
&& y
> rectLevel3
.y
&& level3Selectable
) {
202 else if (x
> rectLevel2
.x
&& y
> rectLevel2
.y
&& level2Selectable
) {
206 else if (x
> rectLevel1
.x
&& y
> rectLevel1
.y
&& level1Selectable
) {
219 if (mouseClicked
&& hoverLevel1
) {
220 //cout << "Fired1\n";
222 *screen
= Level1Screen
;
224 else if (mouseClicked
&& hoverLevel2
) {
225 //cout << "Fired2\n";
227 *screen
= SettingsScreen
;
229 else if (mouseClicked
&& hoverLevel3
) {
230 //cout << "Fired3\n";
232 *screen
= Level3Screen
;
234 else if (mouseClicked
&& hoverLevel4
) {
235 //cout << "Fired4\n";
237 *screen
= SettingsScreen
;
239 else if (mouseClicked
&& hoverRemix
) {
240 //cout << "Fired5\n";
242 *screen
= SettingsScreen
;
244 else if (mouseClicked
&& hoverQuit
) {
245 //cout << "Fired6\n";
247 *screen
= MainMenuScreen
;
252 *screen
= MainMenuScreen
;
256 void LevelSelect::play()
259 hoverAddress
= &hoverLevel1
;
261 else if (hoverLevel2
) {
262 hoverAddress
= &hoverLevel2
;
264 else if (hoverLevel3
) {
265 hoverAddress
= &hoverLevel3
;
267 else if (hoverLevel4
) {
268 hoverAddress
= &hoverLevel4
;
270 else if (hoverRemix
) {
271 hoverAddress
= &hoverRemix
;
273 else if (hoverQuit
) {
274 hoverAddress
= &hoverQuit
;
277 if (mouseClicked
&& (hoverLevel1
|| hoverLevel2
|| hoverLevel3
|| hoverLevel4
|| hoverRemix
|| hoverQuit
)) {
278 rsc
->sptr
->playSFX(0);
280 if (!playedOnce
&& (hoverLevel1
|| hoverLevel2
|| hoverLevel3
|| hoverLevel4
|| hoverRemix
|| hoverQuit
) || hoverAddress
!= hoverAddressOld
) {
281 rsc
->sptr
->playSFX(1);
284 else if (playedOnce
&& (hoverLevel1
|| hoverLevel2
|| hoverLevel3
|| hoverLevel4
|| hoverRemix
|| hoverQuit
)) {
292 hoverAddressOld
= &hoverLevel1
;
294 else if (hoverLevel2
) {
295 hoverAddressOld
= &hoverLevel2
;
297 else if (hoverLevel3
) {
298 hoverAddressOld
= &hoverLevel3
;
300 else if (hoverLevel4
) {
301 hoverAddressOld
= &hoverLevel4
;
303 else if (hoverRemix
) {
304 hoverAddressOld
= &hoverRemix
;
306 else if (hoverQuit
) {
307 hoverAddressOld
= &hoverQuit
;
312 void LevelSelect::render()
314 SDL_RenderClear(renderer
);
316 SDL_RenderCopy(renderer
, rsc
->gameBG
.at(T2BG
), NULL
, NULL
);
319 SDL_RenderCopy(renderer
, outlineAnimation
->itterateAnimation(30), NULL
, &rectLevel1
);
321 else if (hoverLevel2
) {
322 SDL_RenderCopy(renderer
, outlineAnimation
->itterateAnimation(30), NULL
, &rectLevel2
);
324 else if (hoverLevel3
) {
325 SDL_RenderCopy(renderer
, outlineAnimation
->itterateAnimation(30), NULL
, &rectLevel3
);
327 else if (hoverLevel4
) {
328 // SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectLevel4);
330 else if (hoverRemix
) {
331 // SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectRemix);
333 else if (hoverQuit
) {
334 SDL_RenderCopy(renderer
, outlineAnimation
->itterateAnimation(30), NULL
, &rectQuit
);
337 SDL_SetRenderDrawColor(renderer
, 0xff, 0xff, 0xff, 0xff);
338 SDL_RenderCopy(renderer
, textLevel1
, NULL
, &rectLevel1
);
339 if (level1Selectable
) {
340 SDL_RenderDrawRect(renderer
, &rectLevel1Box
);
341 SDL_RenderCopy(renderer
, textLevel1Box
, NULL
, &rectLevel1Box
);
343 SDL_RenderCopy(renderer
, textLevel2
, NULL
, &rectLevel2
);
344 if (level1Selectable
) {
345 SDL_RenderDrawRect(renderer
, &rectLevel2Box
);
346 SDL_RenderCopy(renderer
, textLevel2Box
, NULL
, &rectLevel2Box
);
348 SDL_RenderCopy(renderer
, textLevel3
, NULL
, &rectLevel3
);
349 if (level1Selectable
) {
350 SDL_RenderDrawRect(renderer
, &rectLevel3Box
);
351 SDL_RenderCopy(renderer
, textLevel3Box
, NULL
, &rectLevel3Box
);
353 //SDL_RenderCopy(renderer, textLevel4, NULL, &rectLevel4);
354 if (level1Selectable
) {
355 // SDL_RenderDrawRect(renderer, &rectLevel4Box);
356 // SDL_RenderCopy(renderer, textLevel4Box, NULL, &rectLevel4Box);
358 //SDL_RenderCopy(renderer, textRemix, NULL, &rectRemix);
359 if (remixSelectable
) {
360 // SDL_RenderDrawRect(renderer, &rectRemixBox);
361 // SDL_RenderCopy(renderer, textRemixBox, NULL, &rectRemixBox);
363 SDL_RenderCopy(renderer
, textQuit
, NULL
, &rectQuit
);
365 SDL_SetRenderDrawColor(renderer
, 0x22, 0x22, 0x22, 0x22);
366 SDL_RenderPresent(renderer
);
369 void LevelSelect::close()
371 SDL_DestroyTexture(textLevel1
);
372 SDL_DestroyTexture (textLevel2
);
373 SDL_DestroyTexture (textLevel3
);
374 //SDL_DestroyTexture (textLevel4);
375 //SDL_DestroyTexture(textRemix);
376 SDL_DestroyTexture(textQuit
);